package com.qf.Servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author Wy
 * @version V1.0
 * @Project day41-3
 * @Package ${PACKAGE_NAME}
 * @Description: ${TODO}
 * @Date 2022/5/12 0:05
 */
@WebServlet(name = "Servlet2",urlPatterns = "/login")
public class Servlet2 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                     request.setCharacterEncoding("utf-8");
        String uname = request.getParameter("uname");
        String pwd = request.getParameter("pwd");
        String code = request.getParameter("code");
        HttpSession session = request.getSession();
        String code1 = (String) session.getAttribute("code");
        if("admin".equals(uname)&& "123".equals(pwd)&& code.equals(code1)){
            session.setAttribute("uname",uname);
            response.sendRedirect(request.getContextPath()+"/bookList");
        }else{
            response.sendRedirect(request.getContextPath()+"/1.html");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                    doPost(request, response);
    }
}
